<template>
    <div class='addaddress'>
        <p-navigator text="新增收货地址"/>
        <van-address-edit 
            :area-list="areaList"
            @save="submit"
            show-set-default
            />
    </div>
</template>
<script>
// 引入vant的省市区数据
import { areaList } from '@vant/area-data';
// 导入接口
import { addAddress } from '@/api'
export default {
    methods: {
        submit(e){
            let obj = {
                name: e.name,
                phone: e.tel,
                a_provice: e.province,
                a_city: e.city,
                a_code: e.county,
                a_desc: e.addressDetail,
                is_select: Number(e.isDefault)
            }
            // 调用新增地址接口
            addAddress(obj).then(res => {
                // 判断后端响应的数据code
                if(res.data.code == 1){
                    // 提示
                    this.$toast('添加成功');
                    // 延迟返回
                    setTimeout(() => {
                        this.$router.back()
                    }, 1500);
                }
            })
        }
    },
    data() {
        return {
            areaList
        }
    },
}
</script>
<style lang="">
    
</style>